package com.jm.weibo.ui;

import java.util.List;

import weibo4andriod.Comment;
import weibo4andriod.DirectMessage;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.Toast;

import com.jm.weibo.logic.CommentToMeAdapter;
import com.jm.weibo.logic.DirectMessagesAdapter;
import com.jm.weibo.logic.IWeiboActivity;
import com.jm.weibo.logic.MainService;
import com.jm.weibo.logic.Task;

public class MessageActivity extends Activity implements IWeiboActivity {

	public static final int REF_GET_WEIBO_COMM = 1;// 刷新所有评论信息

	public static final int REF_GET_WEIBO_ATME = 2;// 刷新所有提到我的信息

	public static final int REF_GET_WEIBO_MESSAGE = 3;// 刷新所有私信信息

	private ListView lv;
     
	public static View process;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// 取消标题栏
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		this.setContentView(R.layout.mes);
		init();
		// 获取所有的评论信息                                          TASK_GET_WEIBO_COMMENT
//		Task tsGetComm = new Task(Task.TASK_GET_WEIBO_COMMENT, null);
//		MainService.addNewTask(tsGetComm);
		this.lv = (ListView) this.findViewById(R.id.listView);
	    this.process = this.findViewById(R.id.progress4ListMsg);
	    this.process.setVisibility(View.GONE);
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Log.d("keydown", ".................." + keyCode);
		if (keyCode == 4)// 如果用户按下了返回键
		{
			MainService.promptExitApp(this);
		}
		return true;
	}

	public void init() {
		 
		MainService.allActivity.add(this);
	}

	public void refresh(Object... param) {
		switch ((Integer) param[0]) {
		case REF_GET_WEIBO_COMM:// 评论列表
			List<Comment> cmms = (List<Comment>) param[1];
			// 定义数据适配器
			CommentToMeAdapter commentToMeAdapter = new CommentToMeAdapter(this, cmms);
			lv.setAdapter(commentToMeAdapter);
			MessageActivity.process.setVisibility(View.GONE);
			break;
			
		case REF_GET_WEIBO_ATME:// 提到我的
             Toast.makeText(this, "提到我的", Toast.LENGTH_SHORT).show();
             MessageActivity.process.setVisibility(View.GONE);
			break;
			
		case REF_GET_WEIBO_MESSAGE:// 私信列表
			List<DirectMessage> alldm = (List<DirectMessage>) param[1];
			// 定义数据适配器
			DirectMessagesAdapter dma = new DirectMessagesAdapter(this, alldm);
			lv.setAdapter(dma);
			MessageActivity.process.setVisibility(View.GONE);
		}
	}

	// 获取所有的评论信息
	public static void getAllComment() {
		Task tsGetComm = new Task(Task.TASK_GET_WEIBO_COMMENT, null);
		MainService.addNewTask(tsGetComm);
	}

	// 获取所有私信
	public static void getAlldirectMessage() {
		// 获取所有的评论信息
		Task tsGetComm = new Task(Task.TASK_GET_WEIBO_MESSAGE, null);
		MainService.addNewTask(tsGetComm);
	}

}
 
